//
//  GIFTableViewCell.m
//  FVQuickMessage
//
//  Created by dllo on 16/8/22.
//  Copyright © 2016年 zty. All rights reserved.
//

#import "GIFTableViewCell.h"
#import "LHMGetHeightTool.h"
#import "SmileModel.h"
#import "UIImage+GIF.h"
#import "LHMScanImageView.h"

@interface GIFTableViewCell ()

@property (nonatomic, retain) UILabel *titleLabel;

@property (nonatomic, retain) UIImageView *gifImageView;

@end

@implementation GIFTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.titleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_titleLabel];
        
        self.gifImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_gifImageView];
    }
    return self;
}

-(void)layoutSubviews {
    
    [super layoutSubviews];
    
    NSString *str = [NSString stringWithFormat:@"%@", self.smileModel.text];
    
    CGFloat titleHeight = [LHMGetHeightTool heightWith:str];
    
    self.titleLabel.frame = CGRectMake(10, 35, self.contentView.bounds.size.width - 20, titleHeight);
    self.titleLabel.numberOfLines = 0;
    self.titleLabel.backgroundColor = [UIColor whiteColor];
    
    
    // NSArray *images = [self.bigModel.gif objectForKey:@"gif_thumbnail"];
    
    // NSString *image = [images objectAtIndex:0];
    
    // CGFloat gifHeight = [LHMGetHeightTool twoHeightWith:image];
    
    self.gifImageView.frame = CGRectMake(10, titleHeight + 35, self.contentView.bounds.size.width - 20, 200);
    
    UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(scanGifImage:)];
    
    [_gifImageView addGestureRecognizer:tapGes];
    
    self.gifImageView.userInteractionEnabled = YES;
    
}

-(void)setSmileModel:(SmileModel *)smileModel {
    
    if (_smileModel != smileModel) {
        _smileModel = smileModel;
    }
    
    self.titleLabel.text = smileModel.text;
    
    // 动图栏
    NSArray *imagesArray = [self.smileModel.gif objectForKey:@"images"];
    
    NSString *imageStr = [imagesArray objectAtIndex:0];
    
    NSURL *imageURL = [NSURL URLWithString:imageStr];
    
    NSData *gifData = [NSData dataWithContentsOfURL:imageURL];
    
    
    
    self.gifImageView.image = [UIImage sd_animatedGIFWithData:gifData];
    
}

-(void)scanGifImage:(UITapGestureRecognizer *)tap {
    
    NSLog(@"点击动图");
    UIImageView *clickImageView = (UIImageView *)tap.view;
    [LHMScanImageView scanBigImageWithImageVIew:clickImageView];
    
}


@end
